package com.chenfan.mcn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfan.mcn.dao.QuarterMapper;
import com.chenfan.mcn.model.Quarter;
import com.chenfan.mcn.model.vo.QuarterVO;
import com.chenfan.mcn.service.QuarterService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lizhejin
 * @since 2021-04-16
 */
@Service
public class QuarterServiceImpl extends ServiceImpl<QuarterMapper, Quarter> implements QuarterService {

    @Override
    public List<Quarter> getQuarter() {
        List<Quarter> quarters = baseMapper.getQuarter();
        return quarters;
    }

    @Override
    public List<QuarterVO> getAll() {
        List<QuarterVO> quarterList = baseMapper.getAll();
        Date now = new Date();
        quarterList.stream().forEach(quarter -> {
            boolean isCurrentQuarter = now.compareTo(quarter.getStartTime()) >= 0 && now.compareTo(quarter.getEndTime()) <= 0;
            if (isCurrentQuarter) {
                quarter.setIsCurrent(Boolean.TRUE);
            } else {
                quarter.setIsCurrent(Boolean.FALSE);
            }
        });
        return quarterList;
    }

    @Override
    public List<Quarter> getBeforeList() {
        List<Quarter> quarters = baseMapper.getBeforeList();
        return quarters;
    }
}
